package top.linyuxb.lycloud.samples.client1.controller;


import com.alibaba.fastjson2.JSONObject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import top.linyuxb.lycloud.common.constant.LyRpcRobinType;
import top.linyuxb.lycloud.rpc.starter.annotation.LyRpcReference;
import top.linyuxb.lycloud.rpc.starter.annotation.LyRpcRibbon;
import top.linyuxb.lycloud.samples.config.service.IClientService;
import top.linyuxb.lycloud.samples.config.service.IClientService2;
import top.linyuxb.lycloud.samples.config.service.IServerService;

/**
 * @author linyuxb
 * @date 2024/1/13 4:20 下午
 * @desc
 */
@RestController
public class DemoController {
    @LyRpcReference(version = "002")
    private IClientService clientService;
    @LyRpcReference
    private IClientService2 iClientService2;
    @LyRpcReference(version = "001")
    private IServerService serverService;

    @GetMapping("/clientService")
    @LyRpcRibbon
    public JSONObject clientService() {
        JSONObject json = new JSONObject();
        json.put("name", "张三");
        json.put("school", "惠民小学");
        return clientService.test("锄禾日当午", json);
    }

    @GetMapping("/clientService2")
    @LyRpcRibbon(ribbonType = LyRpcRobinType.RANDOM)
    public String clientService2() {
        return iClientService2.getSchool("床前明月光", 25);
    }

    @GetMapping("/serverService")
    @LyRpcRibbon(ribbonType = LyRpcRobinType.IP_HASH)
    public JSONObject serverService() {
        return serverService.test("春种一粒粟", 14, Boolean.TRUE);
    }

}
